<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>登录</title>
	<!-- 样 式 文 件 -->
	<link rel="stylesheet" href="component/pear/css/pear.css" />
	<link rel="stylesheet" href="admin/css/other/login.css" />
	<!-- 资 源 引 入 -->
	<script src="component/layui/layui.js"></script>
	<script src="component/pear/pear.js"></script>
</head>
<!-- 代 码 结 构 -->

<body background="admin/images/background.svg" style="background-size: cover;">
	<form class="layui-form" action="javascript:void(0);">
		<div class="layui-form-item">
			<img class="logo" src="admin/images/logo.jpg" />
			<div class="title">furion基础权限管理</div>
			<div class="desc">
				xxxxx版权所有&copy;
			</div>
		</div>
		<div class="layui-form-item">
			<input type="text" placeholder="请输入账号" name="account" hover class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input type="password" placeholder="请输入密码" name="password" lay-verify="password" hover class="layui-input" />
		</div>
		<div class="layui-form-item">
			<button type="submit" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
				登 入
			</button>
		</div>
	</form>
</body>

</html>

<script>
	layui.use(['form', 'jquery', 'button', 'popup', 'context'], function () {
		var form = layui.form;
		var button = layui.button;
		var popup = layui.popup;
		var $ = layui.jquery;
		var context = layui.context;

		var basePath = context.get("base-path");


		form.verify({
			account: function (value, item) {
				if (value.length < 2) return '账户至少输入2位字符';
			},
			password: function (value) {
				if (value.length < 5) return '密码至少输入5位字符';
			}
		});

		form.on('submit(login)', function (data) {
			var btn = button.load({ elem: '.login' })
			$.ajax({
				url: basePath + '/api/system/authorize/login',
				data: JSON.stringify(data.field),
				dataType: 'json',
				contentType: 'application/json',
				type: 'post',
				success: function (result) {
					if (result.succeeded) {
						popup.success("登录成功", function () {
							btn.stop();
							location.href = "index.html";
							// 将 token 存储 localStore，传输格式如下
							//Authorization: Bearer 你的token
							//X-Authorization: Bearer 你的刷新token
							context.put("token", "Bearer " + result.data)
						});
					} else {
						btn.stop();
						popup.failure(JSON.stringify(result.errors));
					}
				}
			})
			return false;
		});
	})
</script>